const parser = require("@babel/parser");
const template = require("@babel/template").default;
const traverse = require("@babel/traverse").default;
const t= require("@babel/types");
const generator = require("@babel/generator").default;
const fs = require('fs');
var content =fs.readFileSync("./source1.js",{ "encoding": 'utf-8' })
var ast =parser.parse(content)

const visitor={
    IfStatement(path)
    {
        let {node,parent}=path;
        if (node.test.type=="BinaryExpression"){
            {
                if(node.test.left.value == node.test.right.value)  //"wxqXe" === "wxqXe"
                {
                    switch (node.test.operator) {
                        case "!==":
                            for (var idx = 0; idx < node.consequent.body.length; idx++) {
                            parent.body.splice(parent.body.indexOf(node), 0, node.consequent.body[idx]);
                            }
                            parent.body.splice(parent.body.indexOf(node), 1);
                            break
                        case '===' : //if('aaa'==='aaa'){}
                            for (var idx = 0; idx < node.alternate.body.length; idx++) {
                                parent.body.splice(parent.body.indexOf(node), 0, node.alternate.body[idx]);
                            }
                            parent.body.splice(parent.body.indexOf(node), 1);
                            break
                    }
                }else{
                    switch (node.test.operator) {
                        case '!==' : //if('aaa'!=='bbb'){}
                            for (var idx = 0; idx < node.consequent.body.length; idx++) {
                                parent.body.splice(parent.body.indexOf(node), 0, node.consequent.body[idx]);
                            }
                            parent.body.splice(parent.body.indexOf(node), 1);
                            break

                        case '===' : //if('aaa'==='bbb'){}
                            for (var idx = 0; idx < node.alternate.body.length; idx++) {
                                parent.body.splice(parent.body.indexOf(node), 0, node.alternate.body[idx]);
                            }
                            parent.body.splice(parent.body.indexOf(node), 1);
                            break

                    }
                }
            }
        }
    }

}


traverse(ast,visitor)
let { code } = generator(ast);
console.log(code);